/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nominalitzacions.persistance;

import java.io.FileNotFoundException;
import java.io.IOException;
import nominalitzacions.domain.NominalizatorDictionary;
import nominalitzacions.domain.UrlDomainController;

/**
 *
 * @author marc.mauri
 */
public class NominalizatorDictionaryPersistanceController {

    private String USER_HOME;
    private String SYSTEM_SLASH;
    private String DICTIONARY_DIRECTORY;
    private UrlDomainController UDC;
    public NominalizatorDictionaryPersistanceController() {
        UDC = new UrlDomainController();
        USER_HOME = UDC.getRoot();
        SYSTEM_SLASH = System.getProperty("file.separator");
        DICTIONARY_DIRECTORY = UDC.getLanguages();
    }

    public NominalizatorDictionary loadDictionary(String type) {
        DictionaryDataManager DDM = new DictionaryDataManager(DICTIONARY_DIRECTORY +
                                                                type);
        NominalizatorDictionary d = null;
        try {
            d = DDM.loadDictionary();
        } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage() );
        }
        return d;
    }

    public NominalizatorDictionary loadDictionaryFromPath(String path) {
        DictionaryDataManager DDM = new DictionaryDataManager(path);
        NominalizatorDictionary d = null;
        try {
            d = DDM.loadDictionary();
        } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage() );
        }
        return d;
    }

    public boolean newDictionary(String languageName, String type) throws IOException {
        DictionaryDataManager DDM = new DictionaryDataManager(DICTIONARY_DIRECTORY +
                                                                languageName +
                                                                SYSTEM_SLASH +
                                                                type);
        return DDM.newDictionary();
    }

    public void storeDictionary(NominalizatorDictionary d) throws IOException {
        DictionaryDataManager DDM = new DictionaryDataManager(DICTIONARY_DIRECTORY +
                                                            d.getLanguageName() +
                                                            SYSTEM_SLASH +
                                                            d.getType() );
        DDM.storeDictionary(d);
    }

    public boolean deleteDictionary(String languageName, String type) throws IOException {
        DictionaryDataManager DDM = new DictionaryDataManager(DICTIONARY_DIRECTORY +
                                                            languageName +
                                                            SYSTEM_SLASH +
                                                            type);
        return DDM.deleteDictionary();
    }


}

